package rs.pnv.model.insurance;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotBlank;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_TRAVEL_HELP_INSURANCE")
@XmlAccessorType(XmlAccessType.FIELD)
public class TravelHelpInsurance extends AbstractEntity {

	public enum TravelHelpPackage {
		TOWING, // šlepovanje
		FIXING,
		HOTEL_ACCOMODATION,
		ALTERNATIVE_TRANSPORT
	}

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private Integer duration;

	@NotBlank
	@Column(nullable = false)
	@XmlElement(nillable = false)
	private TravelHelpPackage travelHelpPackage;

	@NotBlank
	@OneToOne
	@JoinColumn(nullable = false)
	@XmlElement(nillable = false)
	private Vehicle vehicle;

	public TravelHelpInsurance() {

	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public TravelHelpPackage getTravelHelpPackage() {
		return travelHelpPackage;
	}

	public void setTravelHelpPackage(TravelHelpPackage travelHelpPackage) {
		this.travelHelpPackage = travelHelpPackage;
	}

	public Vehicle getVehicle() {
		return vehicle;
	}

	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(duration)
				.append(travelHelpPackage)
				.append(vehicle)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final TravelHelpInsurance otherTravelHelpInsurance = (TravelHelpInsurance) obj;

		return new EqualsBuilder()
				.append(duration, otherTravelHelpInsurance.getDuration())
				.append(travelHelpPackage, otherTravelHelpInsurance.getTravelHelpPackage())
				.append(vehicle, otherTravelHelpInsurance.getVehicle())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("duration", duration)
				.append("travelHelpPackage", travelHelpPackage)
				.append("vehicle", vehicle)
				.append(super.toString())
				.toString();
	}

}
